package com.stox.client.ui.javafx.watchlist.widget;

import javafx.event.ActionEvent;

import com.stox.client.api.core.Client;
import com.stox.client.ui.javafx.core.util.CSS;
import com.stox.client.ui.javafx.core.util.UI;
import com.stox.shared.core.i18n.MessageSource;
import com.stox.shared.watchlist.model.Watchlist;


public class DeleteWatchlistButton extends AbstractWatchlistButton {
	
	public DeleteWatchlistButton(WatchlistComboBox watchlistComboBox) {
		super(watchlistComboBox);
		setText(MessageSource.get("Delete"));
		UI.control(this, MessageSource.get("Delete.Watchlist"), true, false, CSS.red);
	}
	
	@Override
	public void handle(ActionEvent event) {
		Watchlist watchlist = getWatchlistComboBox().getSelectionModel().getSelectedItem();
		if(null != watchlist){
			Client.WATCHLIST.delete(watchlist.getId());
			getWatchlistComboBox().getItems().remove(watchlist);
			if(!getWatchlistComboBox().getItems().isEmpty()){
				getWatchlistComboBox().getSelectionModel().clearAndSelect(0);
			}
		}
	}
	
}
